//
//  VCServer.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/3/9.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VCServer: VCBase {
    
    private lazy var serverView:ServerView = {
        let ui = ServerView()
        let uiY = realHeight + MARGIN10
        ui.delegate = self
        ui.frame = CGRect(x: 0, y: uiY, width: SCREEN_WIDTH, height: SCREEN_HEIGHT - uiY)
        return ui
    }()
    
    private lazy var serverItemView: ServerItemView = {
        let ui = ServerItemView()
        ui.delegate = self
        ui.frame = view.frame
        return ui
    }()
           
    override func viewDidLoad() {
        super.viewDidLoad()
        
        init_view()
    }
}

extension VCServer: ServerItemViewDelegate {
    
    func server_item_remove() {
        serverItemView.removeFromSuperview()
    }
    
    func server_item_url(url: String) {
        self.serverView.resetInputUrl = url
        serverItemView.removeFromSuperview()
    }
}

extension VCServer:ServerViewDelegate {
    
    func server_url(url: String?) {
        if url?.count == 0 {
            self.show(text: "服务器地址不能为空")
            self.serverView.resetInputUrl = SP_INNTER
            return
        }
        UserDefaults.standard.setValue(url, forKey: SP_IP)
        self.navigationController?.popViewController(animated: true)
    }
    
    func server_click_down_arrow() {
        view.endEditing(true)
        view.addSubview(serverItemView)
    }
}

extension VCServer {
    
    private func init_view() -> Void {
        view.addSubview(serverView)
    }
}
